package a.codetop;

public class _18交替打印 {

    static String suo="suo";

    public static void main(String[] args) throws InterruptedException{

        new Thread(()->{
            synchronized(suo){
                for (int i = 0; i < 3; i++) {
                    System.out.println("A");
                    suo.notifyAll();
                    try {suo.wait();} catch (InterruptedException e) {e.printStackTrace();}
                }
            }
        }).start();

        new Thread(()->{
            synchronized(suo){
                for (int i = 0; i < 3; i++) {
                    System.out.println("B");
                    suo.notifyAll();
                    try {suo.wait();} catch (InterruptedException e) {e.printStackTrace();}
                }
            }
        }).start();

    }

}
